package net.samsb.request.execute;

import android.os.Message;

import com.alibaba.fastjson.JSON;

import net.samsb.BaseApplication;
import net.samsb.log.LogUtils;
import net.samsb.model.DoorEntity;
import net.samsb.tool.HttpClient;

import java.io.IOException;
import java.util.List;

import okhttp3.Response;

public class DoorExecute implements HttpClient {

    private Message  message;

    @Override
    public void onSucceed(int what, Response response, int arg) {


        List<DoorEntity> doorEntityList = null;

            try {
                doorEntityList = JSON.parseArray(response.body().string(), DoorEntity.class);

                message = BaseApplication.mHandler
                        .getHandlerWithName("MainActivity")
                        .obtainMessage();

                message.what = what;
                message.obj = doorEntityList;
                message.arg1 = arg;

                BaseApplication.mHandler
                        .getHandlerWithName("MainActivity")
                        .sendMessage(message);

//                for (DoorEntity doorEntity : doorEntityList) {
//                    Log.e("DOORLIST", doorEntity.getCrkzwmc());
//                }

            } catch (IOException e) {
                e.printStackTrace();
            }

    }

    @Override
    public void onFailed(int what, String msg) {

        LogUtils.e("DoorExecute错误", msg);

        Message  message = BaseApplication.mHandler
                .getHandlerWithName("MainActivity")
                .obtainMessage();

        message.what = what;
        message.obj = msg;

        BaseApplication.mHandler
                .getHandlerWithName("MainActivity")
                .sendMessage(message);
    }
}
